package com.coocaa.typhoon.api.v1.userfile.util;

import cn.hutool.core.io.file.FileNameUtil;
import com.coocaa.cirrus.common.base.util.IdCreateUtil;
import lombok.experimental.UtilityClass;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author bijiahao
 * @date : 2025/9/18 15:37
 * @description
 */
@UtilityClass
public class TosUploadFilePathUtil {
    /**
     * {envDir}/{fileName}
     *
     * @param envDir
     * @param fileName
     * @return
     */
    public static String getRemoteUploadFilePath(String envDir, String fileName) {
        StringBuffer sb = new StringBuffer();
        sb.append(envDir).append("/")
                .append(fileName);
        return sb.toString();
    }

    /**
     * {envDir}/{ FileNameUtil.mainName(parentFileName)}_{parentFileExtName}_{fileScene}_{index}.{fileExtName}
     *
     * @param envDir
     * @param parentFileName
     * @param index
     * @param fileExtName
     * @return
     */
    public static String getRemoteUploadFilePathForRlsFile(String envDir, String parentFileName, int index, String fileExtName, String fileScene) {
        StringBuffer sb = new StringBuffer();
        String fileNameTrimSuffix = FileNameUtil.mainName(parentFileName);
        String parentFileExtName = FileNameUtil.extName(parentFileName);
        sb.append(envDir).append("/")
                .append(fileNameTrimSuffix)
                .append("_").append(parentFileExtName.toUpperCase())
                .append("_").append(fileScene)
                .append("_").append(index)
                .append(".").append(fileExtName);
        ;
        return sb.toString();
    }


    public static String getLocalSaveFilePath(String localDir, String fileName) {
        StringBuffer sb = new StringBuffer();
        sb.append(localDir).append("/").append(fileName);
        return sb.toString();
    }

    /**
     * {yyyyMMdd}_{IdCreateUtil.getStrId()}.{fileExtName}
     *
     * @param fileExtName
     * @return
     */
    public static String getFileName(String fileExtName) {
        LocalDate now = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        StringBuffer sb = new StringBuffer();
        sb.append(now.format(formatter))
                .append("_")
                .append(IdCreateUtil.getStrId())
                .append(".")
                .append(fileExtName)
        ;
        return sb.toString();
    }

    public static void main(String[] args) {
        String t = "test/5618318815881752.jpg";
        System.out.println(FileNameUtil.extName(t));
        System.out.println(FileNameUtil.mainName(t));
        System.out.println(FileNameUtil.getSuffix(t));
        System.out.println(FileNameUtil.getName(t));
    }

}
